<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
  <div style="height: 200px">
    <a-date-picker
      format="YYYY"
      mode="year"
      :value="year"
      :open="open"
      @openChange="openChange"
      @panelChange="panelChange"
    />
  </div>

  </j-modal>
</template>

<script>
  import { judgeSjrq } from '@/utils/util'
  import { httpAction } from '@/api/manage'
  import { downFile } from '@/api/manage'
  import moment from 'moment'

  export default {
    name: 'editCalendarModal',
    components: {
    },
    data () {
      return {
        open: false,
        year: moment(),
        model:{
        },
        fileName: '',
        sjrq:'',
        params:{},
        title:'编辑',
        width:900,
        visible: false,
        disableSubmit: false
      }
    },
    props: {
      handleAdd: {
        type: Function,
        default: null
      }
    },
    methods: {
      moment,
      //Ant Design封装年份选择组件
      openChange(status) {
        if (status) {
          this.open = true;
        } else {
          this.open = false;
        }
      },
      panelChange(value){
        this.year = value;
        this.open = false;
      },
      getCurrentData(){
        return moment(new Date().toLocaleDateString(), this.dateFormat)
      },
      onChange(date, dateString) {
        this.sjrq = dateString
      },
      showModal() {
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk(e) {
        let date = moment(this.year).format('YYYY');
          let fileName = "日历管理数据";
          downFile("/sendMsg/sendMsgDate/exportXls",{"sjrq":date}).then((data)=>{
            if (!data) {
              this.$message.warning("文件下载失败")
              return
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
              window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
            }else{
              let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
              let link = document.createElement('a')
              link.style.display = 'none'
              link.href = url
              link.setAttribute('download', fileName+'.xlsx')
              document.body.appendChild(link)
              link.click()
              document.body.removeChild(link); //下载完成移除元素
              window.URL.revokeObjectURL(url); //释放掉blob对象//关闭窗口
              this.handleCancel();
            }
          })



       /* let rq = moment(new Date().toLocaleDateString()).format("YYYY-MM-DD");
        if(this.sjrq == ''){
          this.sjrq = rq
        }
        if(this.sjrq == undefined || this.sjrq == ''){
          this.$message.warning("请选择数据日期")
          return;
        }
        if(!this.fileName || typeof this.fileName != "string"){
          this.fileName = "导出文件"
        }
        let downloadUrl = this.$parent.$parent.url.exportXlsUrl;
        this.params.sjrq = this.sjrq;
        let param = this.params;*/
      /*  */

      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.sjrq = '';
        this.close()
      },
    }
  }
</script>